package com.jx.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jx.mapper.CarMapper;
import com.jx.po.CarInfo2Jylsh;
import com.jx.vo.CarVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarService extends ServiceImpl<CarMapper, CarInfo2Jylsh> {

    public IPage getCars(IPage page,CarVo carVo) {

        return page(page, createWrapper(carVo));


    }

    private QueryWrapper createWrapper(CarVo carVo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (carVo == null) {
            return queryWrapper;

        }
        queryWrapper.like(StringUtils.isNotEmpty(carVo.getHphm()), CarInfo2Jylsh.Fields.hphm, carVo.getHphm());
        queryWrapper.like(StringUtils.isNotEmpty(carVo.getJylsh()), CarInfo2Jylsh.Fields.jylsh,carVo.getJylsh());
        return queryWrapper;
    }
}
